package xby.study.proxy.cglib.fixedvalue;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.FixedValue;
import xby.study.proxy.cglib.PathUtil;

public class FixedValueTest {

    public void f() {
        System.out.println("...f()...");
    }

    public void g() {
        System.out.println("...g()...");
    }

    public void h() {
        System.out.println("...h()...");
    }

    public static void main(String[] args) {
        // 配置class文件的输出目录
         System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, PathUtil.getOutPath(FixedValueTest.class));

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(FixedValueTest.class);


        enhancer.setCallback(new FixedValue() {
            @Override
            public Object loadObject() throws Exception {
                System.out.println("所有的方法都不调用了！！！ 都调我！！");
                return null;
            }
        });
        FixedValueTest test = (FixedValueTest) enhancer.create();
        test.f();
        test.g();
        test.h();
    }
}
